#region Header
//=============================================================================
//                          GShield (Game Shield)
//=============================================================================
//
// Original Programmer: Shawn Jackson
// Company: WaveTech Digital Technologies (www.wtdt.com)
// Copyright: (c) 2006 WaveTech Digital Technologies, All Rights Reserved.
// Assembly: Engine
// Code File Name: Logging.cs
// Code File Date: 5/24/2007
//
// Code File Info: Broker between the logging implementaiton and the application.
//=============================================================================
/*
 * UPDATES
 * -------
 */
#endregion Header

#region License
/*
  GShield - Game Shield
  Copyright (C) 2006-2007 WaveTech Digital Technologies, Inc.
                                http://www.wtdt.com

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
#endregion License

#region Includes

using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using WaveTech.GShield.Model;

#endregion Includes

namespace WaveTech.GShield.Engine.Systems
{
	/// <summary>
	/// Stub Class for the Logging Interface. Abstracts the logging system
	/// from the implementation.
	/// </summary>
	public static class Logging
	{
		public static void Write(string message)
		{
			Logger.Write(message);
		}

		public static void Write(string message, string category)
		{
			Logger.Write(message, category, 0, (int)LogType.System, TraceEventType.Information, category);
		}

		public static void Write(string message, string category, LogPriority priority)
		{
			Logger.Write(message, category, (int)priority, (int)LogType.System, TraceEventType.Information, category);
		}

		public static void Write(string message, string category, LogPriority priority, LogType eventId)
		{
			Logger.Write(message, category, (int)priority, (int)eventId, TraceEventType.Information, category);
		}

		public static void Write(string message, string category, LogPriority priority, LogType eventId, string userName)
		{
			WriteEntry(message, new string[] { category }, priority, eventId, TraceEventType.Information, category, userName);
		}

		public static void Write(string message, string category, LogPriority priority, LogType eventId, TraceEventType severity)
		{
			Logger.Write(message, category, (int)priority, (int)eventId, severity, category);
		}

		public static void Write(string message, string category, LogPriority priority, LogType eventId, TraceEventType severity, string title)
		{
			Logger.Write(message, category, (int)priority, (int)eventId, severity, title);
		}

		private static void WriteEntry(string message, ICollection<string> categories, LogPriority priority, LogType eventId, TraceEventType severity, string title, string userName)
		{
			LogEntry log = new LogEntry();
			log.Message = message.ToString();
			log.Categories = categories;
			log.Priority = (int)priority;
			log.EventId = (int)eventId;
			log.Severity = severity;
			log.Title = title;

			if (userName != null && userName.Length > 0)
				log.MachineName = userName;
		}
	}
}
